/**
 * User domain class.
 */
class User {
    static transients = ['pass','inviteCode']
    static hasMany = [authorities: Role, topics: Topic, opinions: Opinion, topicSpeakerShips: TopicSpeakerShip]
    static belongsTo = Role

    /** Username */
    String username
    /** MD5 Password */
    String passwd
    /** enabled */
    boolean enabled
	
    String email
    boolean emailShow
	
    /** plain password to create a MD5 password */
    String pass = '[secret]'
	
    Profile profile
	
    static constraints = {
        username(blank: false, unique: true, size:4..16)
        passwd(blank: false)
        enabled()
        profile(nullable: true)
    }
	
    static mapping = {
		
    }

    static mappedBy = [topics:"owner",opinions:"author"]

    String toString() {
		"$username,$email"
    }

    def speakerTopics() {
        return topicSpeakerShips.collect{it.topic}
    }

    def addSpeakTopic(Topic topic) {
        TopicSpeakerShip.link(this,topic)
        return speakerTopics()
    }

    def removeSpeakTopic(Topic topic) {
        TopicSpeakerShip.unlink(this,topic)
        return speakerTopics()
    }
}
